Grokking Microservices Design Patterns
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
Who Should Take This Course?
The Course at a Glance
Strangler Fig Pattern
Introduction
The Problem: Legacy Systems
The Strangler Pattern: A Solution
The Architecture of the Strangler Pattern
Strangler Pattern: A Detailed Example
Key Insights and Implications
Introduction to the API Gateway Pattern
Advantages of API Gateway Pattern
API Gateway Pattern: An Example
Performance Implications
System Design Example
Introduction to BFF
The Problem: Traditional Backend Models
The Architecture of the BFF Pattern
BFF Pattern: An Example
Performance Implications
System Design Examples
What is Service Discovery Pattern?
The Problem: Service Coordination in Distributed Systems
Service Discovery Pattern: A Solution
The Architecture of the Service Discovery Pattern
The Inner Workings of the Service Discovery Pattern
Service Discovery Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Security Considerations
Introduction
The Problem: The Struggles of Distributed Systems and Service Failures
The Circuit Breaker Pattern: An Effective Shield Against Cascading Failures
Circuit Breaker Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Summary
Introduction
The Problem: Failure Propagation in Distributed Systems
The Bulkhead Pattern: A Solution
The Architecture
The Inner Workings
Bulkhead Pattern: A Example
Performance Implications and Special Considerations
System Design Examples
Conclusion
Introduction
The Retry Pattern: A Solution to Unreliable External Resources
The Architecture of the Retry Pattern
Retry Pattern: An Example
Performance Implications
Use Cases and System Design Examples
Conclusion
Introduction to the Sidecar Pattern
The Problem: Monolithic Application Management
A Solution to the Monolithic Mayhem
The Architecture of the Sidecar Pattern
Sidecar Pattern: Bringing Theory to Practice with an Example
Performance Implications
System Design Examples: Bringing the Sidecar Pattern to Life
Introduction to Saga Pattern
The Problem: Traditional Transaction Models
The Saga Pattern: A Solution
The Architecture of the Saga Pattern
The Inner Workings of the Saga Pattern
Saga Pattern: A Example
Performance Implications
System Design Examples
Conclusion
Introduction
The Problem: Managing Complex Interactions in Distributed Systems
Event-Driven Architecture: A Promising Solution
The Architecture of the Event-Driven Architecture Pattern
The Inner Workings of the Event-Driven Architecture Pattern
Event-Driven Architecture Pattern: An Example
Performance Implications and Special Considerations
Use Cases and System Design Examples
Conclusion
Introduction
The Problem: Traditional CRUD Operations
CQRS Pattern: A Solution
The Architecture of the CQRS Pattern
The Inner Workings of the CQRS Pattern
CQRS Pattern: An Example
Issues, Special Considerations, and Performance Implications
System Design Examples
Introduction
The Problem: Configuration Management in a Microservices Architecture
The Solution: Configuration Externalization Pattern
Unveiling the Architecture: How Does Configuration Externalization Work?
Delving into Code: An Example
Considerations and Implications
Use Cases and Real-world Examples
Conclusion
Embrace the Future of Software Architecture
Strangler Pattern: A Detailed Example

Let's work on a Java code example that puts the Strangler Pattern into action.

Setting the Stage: The Legacy System

First, let's set the stage with a simple example of a legacy system. Imagine a basic class, LegacySystem, which has methods for createAccount(), deposit(), withdraw(), and checkBalance(). Here's how this class might look:

public class LegacySystem { public void createAccount(String name) { // ...Old logic for creating an account... } public void deposit(int amount) { // ...Old logic for depositing money... } public void withdraw(int amount) { // ...Old logic for withdrawing money... } public int checkBalance() { // ...Old logic for checking balance... return 0; // placeholder } }

Creating the New System

Next, let's introduce our new system, appropriately named NewSystem. It will have the same methods but with updated logic:

public class NewSystem { public void createAccount(String name) { // ...New logic for creating an account... } public void deposit(int amount) { // ...New logic for depositing money... } public void withdraw(int amount) { // ...New logic for withdrawing money... } public int checkBalance() { // ...New logic for checking balance... return 0; // placeholder } }

The Facade Interface

Now, it's time to bring in our star player, the Facade Interface. This is the class that will be used by the outside world to interact with our system. It has an instance of both the legacy and the new system, and directs the requests accordingly.

At first, all requests are sent to the legacy system. But as we implement new functionality in the new system, the Facade Interface starts redirecting those requests to the new system.

Here's what our BankingFacade could look like:

public class BankingFacade { private LegacySystem legacySystem; private NewSystem newSystem; public BankingFacade(LegacySystem legacySystem, NewSystem newSystem) { this.legacySystem = legacySystem; this.newSystem = newSystem; } public void createAccount(String name) { if(newSystemReadyFor("createAccount")){ newSystem.createAccount(name); } else { legacySystem.createAccount(name); } } public void deposit(int amount) { if(newSystemReadyFor("deposit")){ newSystem.deposit(amount); } else { legacySystem.deposit(amount); } } public void withdraw(int amount) { if(newSystemReadyFor("withdraw")){ newSystem.withdraw(amount); } else { legacySystem.withdraw(amount); } } public int checkBalance() { if(newSystemReadyFor("checkBalance")){ return newSystem.checkBalance(); } else { return legacySystem.checkBalance(); } } private boolean newSystemReadyFor(String functionality) { // ...Check if new system is ready for given functionality... return false; // placeholder } }

The BankingFacade class directs the flow of operations between the old and new systems.

The Gradual Transition: Replacing Functionality

Now, let's assume that we've replaced the createAccount functionality in the new system. We update the newSystemReadyFor method to return true for the createAccount functionality. And with that all createAccount requests are now directed to the new system.

As we replace more functionalities, we keep updating the newSystemReadyFor method, and gradually, the new system takes over.

The Architecture of the Strangler Pattern
Key Insights and Implications
Mark as Completed

On this page

Setting the Stage: The Legacy System

Creating the New System

The Facade Interface

The Gradual Transition: Replacing Functionality